<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>gdb | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/112.ad614f41.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/108.a2fecadc.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/118.c6ae6572.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/22.f78666de.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/47.67116354.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/56.62ac9b92.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/68.68f45e5e.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link router-link-active">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link router-link-active">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>gdb</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#⭐️gdb描述" class="sidebar-link">⭐️gdb描述</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#⭐️基础命令" class="sidebar-link">⭐️基础命令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-开启tui模式的gdb" class="sidebar-link">1.开启TUI模式的GDB</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-启动、退出、查看代码" class="sidebar-link">2.启动、退出、查看代码</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_3-断点操作" class="sidebar-link">3.断点操作</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_4-调试命令" class="sidebar-link">4.调试命令</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_5-gdb调试的layout使用" class="sidebar-link">5.gdb调试的layout使用</a></li></ul></li><li><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#⭐️编译器开发" class="sidebar-link">⭐️编译器开发</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-gdb调试gcc的坑✔️" class="sidebar-link">1.gdb调试gcc的坑✔️</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-导入符号表file✔️" class="sidebar-link">2.导入符号表file✔️</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_3-load✔️" class="sidebar-link">3.load✔️</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_3-常见问题" class="sidebar-link">3.常见问题</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_4-细节" class="sidebar-link">4.细节</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_5-组会调试经验（gdb-gdbserver远程调试技术）✔️" class="sidebar-link">5.组会调试经验（gdb+gdbserver远程调试技术）✔️</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_6-gdb使用模拟器（免除远程调试）✔️" class="sidebar-link">6.gdb使用模拟器（免除远程调试）✔️</a></li></ul></li><li><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#⭐️后台开发" class="sidebar-link">⭐️后台开发</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_1-gdb多进程调试" class="sidebar-link">1.gdb多进程调试</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#_2-多线程调试" class="sidebar-link">2.多线程调试</a></li></ul></li><li><a href="/05.Engineer/tool/A2.gdb%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4.html#参考资料" class="sidebar-link">参考资料</a><ul class="sidebar-sub-headers"></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="gdb"><a href="#gdb" class="header-anchor">#</a> gdb</h1> <div class="language-txt line-numbers-mode"><pre class="language-text"><code>&lt;font style=&quot;background:yellow&quot;&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>我们<font style="background:pink;">约定<code>(gdb) 命令</code>，表示该命令在gdb里面调试的意思，不是在bash中运行</font> <ul><li>有人说：厉害的调试需要比开发付出2倍以上的努力</li></ul></li></ul> <blockquote><p>gdb设计哲学</p></blockquote> <p>1.gdb里面也能用Tab来补全</p> <p>2.gdb中使用<code>(gdb) help</code>可以查看各种内置gdb命令语法</p> <p>3.退出gdb使用<code>(gdb) q</code>就行了</p> <h2 id="⭐️gdb描述"><a href="#⭐️gdb描述" class="header-anchor">#</a> ⭐️gdb描述</h2> <p>GDB是由 GNU软件系统社区提供的调试工具，同GcC 配套组成了一套完整的开发环境，GDB 是Linux和许多类Unix系统中的标准开发环境。</p> <p>—般来说，GDB 主要帮助你完成下面四个方面的功能:</p> <ul><li>1．启动程序，可以按照自定义的要求随心所欲的<strong>运行</strong>程序</li> <li>2．可让被调试的程序在所指定的调置的断点处停住（断点可以是条件表达式)</li> <li>3．当程序被停住时，可以检查此时程序中所发生的事</li> <li>4．可以改变程序，将一个BUG产生的影响修正从而测试其他 BUG</li></ul> <p>通常，在为调试而编译时，我们会(）关掉编译器的优化选项（<code>-o</code>)，并打开调试选项（<code>-g</code>)</p> <p>另外， <code>-Wall</code>在尽量不影响程序行为的情况下选项打开所有warning，也可以发现许多问题，避免一些不必要的 BUG。</p> <ul><li><code>gcc -g -Wall program.c -o program</code></li></ul> <p><code>-g</code>选项的作用是在可执行文件中<strong>加入源代码的信息</strong>，比如可执行文件中第几条<strong>机器指令</strong>对应<strong>源代码</strong>的第几行，但并不是把整个源文件嵌入到可执行文件中，所以<font style="background:yellow;">在调试时必须保证gdb能找到源文件</font></p> <h2 id="⭐️基础命令"><a href="#⭐️基础命令" class="header-anchor">#</a> ⭐️基础命令</h2> <ul><li>下面是一些查看函数调用栈信息的GDB命令：
<ul><li>backtrace</li> <li>bt打印当前的函数调用栈的所有信息。如：
<ul><li>在遇到段错误时，输入bt命令，即可跟踪错误，非常好用，方便记忆。可以叫<strong>变态</strong></li></ul></li></ul></li></ul> <h3 id="_1-开启tui模式的gdb"><a href="#_1-开启tui模式的gdb" class="header-anchor">#</a> 1.开启TUI模式的GDB</h3> <p>方法1：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>gdb <span class="token builtin class-name">test</span> -tui
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>方法2：</p> <ul><li>在GDB中使用<code>Ctrl+X+A</code>快捷键，切换TUI模型
<ul><li>自<strong>版本6.1</strong>以来，GDB以名为<font style="background:yellow;">TUI（Terminal User Interface，终端用户界面）</font>的模式提供了基于文本交互和图形用户交互之间的折中方法</li></ul></li></ul> <h3 id="_2-启动、退出、查看代码"><a href="#_2-启动、退出、查看代码" class="header-anchor">#</a> 2.启动、退出、查看代码</h3> <p>启动和退出</p> <ul><li><p>gdb可执行程序</p></li> <li><p>quit</p></li></ul> <p>给程序<strong>设置参数</strong>/<strong>获取设置参数</strong></p> <ul><li><code>set args 10 20</code></li> <li><code>show args</code></li></ul> <p>GDB使用帮助</p> <ul><li>help</li></ul> <p>查看当前文件代码</p> <ul><li><p><code>list/ l</code>(从默认位置显示)</p></li> <li><p><code>list/l行号</code>(从指定的行显示)</p></li> <li><p><code>list/ l函数名</code>(从指定的函数显示)</p></li></ul> <p>查看非当前文件代码</p> <ul><li><p><code>list/ l文件名:行号</code></p></li> <li><p><code>list/ l文件名:函数名</code></p></li></ul> <p>设置显示的行数</p> <ul><li><code>show list/ listsize</code></li> <li><code>set list/ listsize行数</code></li></ul> <h3 id="_3-断点操作"><a href="#_3-断点操作" class="header-anchor">#</a> 3.断点操作</h3> <p>设置断点</p> <ul><li><code>b / break 行号</code> <ul><li>在某行
<ul><li>「break point」设置断点 <code>(gdb) b 15</code></li></ul></li></ul></li> <li><code>b / break 函数名</code> <ul><li>在某个函数名设置：<font style="background:yellow;">大型调试常用</font> <ul><li><code>(gdb) b main</code></li></ul></li></ul></li> <li><code>b/ break 文件名:行号</code> <ul><li>在某文件的某行，断点</li> <li>设置断点，如<code>b main.cpp:31</code>，执行到断点后next单步，step进入函数，continue继续运行</li></ul></li> <li><code>b / break 文件名:函数</code></li></ul> <p>查看断点</p> <ul><li><p><code>i/info b/break</code></p></li> <li><p>查看断点：<code>(gdb) info breakpoints</code></p></li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> info breakpoints 
Num     Type           Disp Enb Address            What
<span class="token number">1</span>       breakpoint     keep y   <span class="token operator">&lt;</span>MULTIPLE<span class="token operator">&gt;</span>
<span class="token number">1.1</span>                         y   0x000000000001d440 <span class="token operator">&lt;</span>driver::main<span class="token punctuation">(</span>int, char**<span class="token punctuation">)</span><span class="token operator">&gt;</span>
<span class="token number">1.2</span>                         y   0x000000000001d790 <span class="token operator">&lt;</span>main<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>删除断点</p> <ul><li><code>d / del / delete 断点编号</code></li></ul> <p>设置断点无效</p> <ul><li><code>dis/ disable 断点编号</code></li></ul> <p>设置断点生效</p> <ul><li><code>ena/enable断点编号</code></li></ul> <p>设置条件断点（一般用在循环的位置)</p> <ul><li><code>b/ break 10 if i==5</code></li></ul> <h3 id="_4-调试命令"><a href="#_4-调试命令" class="header-anchor">#</a> 4.调试命令</h3> <p>运行GDB程序</p> <ul><li><code>start</code>（程序停在第一行）</li> <li><code>run</code>（遇到断点才停）</li></ul> <p>继续运行，到==下一个断点==停</p> <ul><li><code>c/continue</code></li></ul> <p>向下执行一行、多行代码（<font style="background:yellow;"><strong>不会进入</strong>函数体</font>）</p> <ul><li><code>n/next</code></li> <li><code>next 数字</code></li></ul> <p>变量操作</p> <ul><li><code>p/print 变量名</code>（打印变量值）</li> <li><code>ptype 变量名</code>（打印变量类型）</li></ul> <p>向下单步调试（<font style="background:yellow;">遇到函数<strong>进入</strong>函数体</font>）</p> <ul><li><p><code>s/step</code></p></li> <li><p><code>finish（跳出函数体）</code></p></li></ul> <p>自动变量操作</p> <ul><li><code>display 变量名</code>（自动打印指定变量的值）</li> <li><code>i/info display</code></li> <li><code>undisplay 编号</code></li></ul> <p>其它操作</p> <ul><li><code>set var 变量名=变量值</code> （循环中用的较多）</li> <li><code>until</code> （跳出循环）</li></ul> <h3 id="_5-gdb调试的layout使用"><a href="#_5-gdb调试的layout使用" class="header-anchor">#</a> 5.gdb调试的<code>layout</code>使用</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout：用于分割窗口，可以一边查看代码，一边测试。主要有以下几种用法：
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout src：显示源代码窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout asm：显示汇编窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout regs：显示源代码/汇编和寄存器窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout split：显示源代码和汇编窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout next：显示下一个layout
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> layout prev：显示上一个layout
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> Ctrl + L：刷新窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> Ctrl + x，再按1：单窗口模式，显示一个窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> Ctrl + x，再按2：双窗口模式，显示两个窗口
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> Ctrl + x，再按a：回到传统模式，即退出layout，回到执行layout之前的调试窗口
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><ul><li>这样有个弊端，开了两个窗口不能上下切换查看历史命令，怎么解决</li> <li>使用<code>fs next</code>命令切换窗口焦点</li></ul> <h2 id="⭐️编译器开发"><a href="#⭐️编译器开发" class="header-anchor">#</a> ⭐️编译器开发</h2> <h3 id="_1-gdb调试gcc的坑✔️"><a href="#_1-gdb调试gcc的坑✔️" class="header-anchor">#</a> 1.gdb调试gcc的坑✔️</h3> <ul><li>参考资料：<a href="https://dmalcolm.fedorapeople.org/gcc/newbies-guide/debugging.html" target="_blank" rel="noopener noreferrer">https://dmalcolm.fedorapeople.org/gcc/newbies-guide/debugging.html<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul> <p>直接gdb那个生成的gcc是调试gcc的<code>driver</code></p> <ul><li>gcc 二进制文件实际上是一个相对<strong>较小</strong>的“<strong>驱动（driver）”程序</strong>，它解析一些命令行选项，然后调用一个或多个其他程序来完成真正的工作</li></ul> <blockquote><p>使用这个才是调试ccl⭐️⭐️⭐️</p></blockquote> <ul><li>用这条指令就可以了</li> <li>好像直接gdb gcc调试的是<code>gcc driver</code></li> <li><font style="background:yellow;"><code>-wrapper gdb,--args</code> 调试的是真实的</font>编译器<font style="background:yellow;">cc1</font></li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>gcc test.c  -S -Os -wrapper gdb,--args
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><blockquote><p>坑点：<code>gdb,--args</code>必须紧挨着写</p></blockquote> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>XXX@XXX:~/debug_test$ gcc -wrapper gdb, --args whoway.c
gcc: error: unrecognized <span class="token builtin class-name">command</span> line option <span class="token string">'--args'</span>
XXX@XXX:~/debug_test$ gcc -wrapper gdb,--args whoway.c
这样才可以
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h4 id="gdb这样使用后（不需要set-args或者r的时候添加参数了）✔️"><a href="#gdb这样使用后（不需要set-args或者r的时候添加参数了）✔️" class="header-anchor">#</a> gdb这样使用后（不需要set args或者r的时候添加参数了）✔️</h4> <ul><li>直接run就行了</li> <li>记得，调试ccl的时候，不能加-S</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>whoway@XXXX:~/debug_test$ gcc -Os -fldm-stm-optimize test.c -wrapper gdb,--args
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="_2-导入符号表file✔️"><a href="#_2-导入符号表file✔️" class="header-anchor">#</a> 2.导入符号表file✔️</h3> <ul><li><p>file</p></li> <li><p>导入符号表，其实gdb进来，要是读取成功了，就不用这个了</p></li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> <span class="token function">file</span> a.out 
Load new symbol table from <span class="token string">&quot;a.out&quot;</span>? <span class="token punctuation">(</span>y or n<span class="token punctuation">)</span> y
Reading symbols from a.out<span class="token punctuation">..</span>.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="_3-load✔️"><a href="#_3-load✔️" class="header-anchor">#</a> 3.load✔️</h3> <p>load好像可以在调试的时候，换执行文件，具体参考下面</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>whoway@XXX:~/solvelbu/riscv_gcc/output/riscv32/bin$ ./gdb gcc
GNU gdb <span class="token punctuation">(</span>GDB<span class="token punctuation">)</span> <span class="token number">10.1</span>
Copyright <span class="token punctuation">(</span>C<span class="token punctuation">)</span> <span class="token number">2020</span> Free Software Foundation, Inc.
License GPLv3+: GNU GPL version <span class="token number">3</span> or later <span class="token operator">&lt;</span>http://gnu.org/licenses/gpl.html<span class="token operator">&gt;</span>
This is <span class="token function">free</span> software: you are <span class="token function">free</span> to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type <span class="token string">&quot;show copying&quot;</span> and <span class="token string">&quot;show warranty&quot;</span> <span class="token keyword">for</span> details.
This GDB was configured as <span class="token string">&quot;--host=x86_64-pc-linux-gnu --target=riscv32-unknown-elf&quot;</span><span class="token builtin class-name">.</span>
Type <span class="token string">&quot;show configuration&quot;</span> <span class="token keyword">for</span> configuration details.
For bug reporting instructions, please see:
<span class="token operator">&lt;</span>https://www.gnu.org/software/gdb/bugs/<span class="token operator">&gt;</span>.
Find the GDB manual and other documentation resources online at:
    <span class="token operator">&lt;</span>http://www.gnu.org/software/gdb/documentation/<span class="token operator">&gt;</span>.

For help, <span class="token builtin class-name">type</span> <span class="token string">&quot;help&quot;</span><span class="token builtin class-name">.</span>
Type <span class="token string">&quot;apropos word&quot;</span> to search <span class="token keyword">for</span> commands related to <span class="token string">&quot;word&quot;</span><span class="token punctuation">..</span>.

warning: A handler <span class="token keyword">for</span> the OS ABI <span class="token string">&quot;GNU/Linux&quot;</span> is not built into this configuration
of GDB.  Attempting to <span class="token builtin class-name">continue</span> with the default riscv settings.

Reading symbols from rgcc<span class="token punctuation">..</span>.
<span class="token punctuation">(</span>No debugging symbols found <span class="token keyword">in</span> gcc<span class="token punctuation">)</span>		<span class="token comment">#注意，这里没有读入“符号表”信息</span>

<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> target sim
Connected to the simulator.
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> load <span class="token builtin class-name">test</span>
<span class="token builtin class-name">test</span>    test.c  
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> load <span class="token builtin class-name">test</span>
Loading section .text, size 0xc0ee lma 0x10074
Loading section .rodata, size 0x10cc lma 0x1c168
Loading section .eh_frame, size 0x40 lma 0x1e234
Loading section .init_array, size 0x8 lma 0x1e274
Loading section .fini_array, size 0x4 lma 0x1e27c
Loading section .data, size 0x99c lma 0x1e280
Loading section .sdata, size 0x2c lma 0x1ec20
Start address 0x10084
Transfer rate: <span class="token number">450160</span> bits <span class="token keyword">in</span> <span class="token operator">&lt;</span><span class="token number">1</span> sec.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br></div></div><h3 id="_3-常见问题"><a href="#_3-常见问题" class="header-anchor">#</a> 3.常见问题</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> b ira.c:ira
No <span class="token builtin class-name">source</span> <span class="token function">file</span> named ira.c.
Make breakpoint pending on future shared library load? <span class="token punctuation">(</span>y or <span class="token punctuation">[</span>n<span class="token punctuation">]</span><span class="token punctuation">)</span> n
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>出现上述，可能2种情况</p> <ul><li>1.编译文件的时候，没加<code>-g</code></li> <li>2.可能是比如gcc那样，不是调试的ccl</li> <li>3.b只能加在可能执行到的地方，<code>riscv.md</code>好像不行==（待考察）==</li></ul> <h3 id="_4-细节"><a href="#_4-细节" class="header-anchor">#</a> 4.细节</h3> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> b regcprop.c:ldm_stm_replace_p<span class="token punctuation">(</span>rtx_insn const*, rtx, rtx<span class="token punctuation">)</span> 
Function <span class="token string">&quot;ldm_stm_replace_p(rtx_insn const*, rtx, rtx)&quot;</span> not defined <span class="token keyword">in</span> <span class="token string">&quot;regcprop.c&quot;</span><span class="token builtin class-name">.</span>
Make breakpoint pending on future shared library load? <span class="token punctuation">(</span>y or <span class="token punctuation">[</span>n<span class="token punctuation">]</span><span class="token punctuation">)</span> n
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> b regcprop.c:ldm_stm_replace_p
Breakpoint <span class="token number">1</span> at 0x5a39c0: <span class="token function">file</span> /home/whoway/solvelbu/gcc/open_source/gcc-7.3.0/gcc/regcprop.c, line <span class="token number">487</span>.
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="_5-组会调试经验（gdb-gdbserver远程调试技术）✔️"><a href="#_5-组会调试经验（gdb-gdbserver远程调试技术）✔️" class="header-anchor">#</a> 5.组会调试经验（gdb+gdbserver远程调试技术）✔️</h3> <blockquote><p>参考自@<a href="https://github.com/Wilson2334" target="_blank" rel="noopener noreferrer">Wilson2334<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>的总结</p></blockquote> <ul><li><p>第1个bash用qemu开启端口1234「使用beta-qemu用户态加载程序」</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>/home/XXX/buildroot_new/buildroot/output/host/bin/qemu-beta -g <span class="token number">8848</span> test.exe 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（此时该终端处于执行状态...）</p></li> <li><p>第2个bash用gdb调试，在gdb运行起来的时候，在里面开启端口「新建终端使用beta-gdb远程连接qemu」</p></li> <li><p>先加载程序</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>/home/XXX/buildroot_new/buildroot/output/host/bin/beta-linux-gdb test.exe 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li></ul> <ul><li><p>然后使用remote连接端口</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>Reading symbols from test.exe<span class="token punctuation">..</span>.
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> target remote :8848
Remote debugging using :8848
_start <span class="token punctuation">(</span><span class="token punctuation">)</span> at <span class="token punctuation">..</span>/sysdeps/beta/start.S:50
<span class="token number">50</span>              call  load_gp
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> b main
Breakpoint <span class="token number">1</span> at 0x1004e0: <span class="token function">file</span> flw_fsw_fadds_fsubs.c, line <span class="token number">10</span>.
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> print a
<span class="token variable">$1</span> <span class="token operator">=</span> <span class="token number">1.01999998</span>
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> l
<span class="token number">6</span>       int main<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token number">7</span>       <span class="token punctuation">{</span>
<span class="token number">8</span>           float a, b, res_add, res_sub<span class="token punctuation">;</span>
<span class="token number">9</span>
<span class="token number">10</span>          a <span class="token operator">=</span> <span class="token number">1.02</span><span class="token punctuation">;</span>
<span class="token number">11</span>          b <span class="token operator">=</span> <span class="token number">2.01</span><span class="token punctuation">;</span>
<span class="token number">12</span>          foo<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token number">13</span>          <span class="token builtin class-name">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token number">14</span>      <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div></li> <li><p>补充资料：gdb+gdbserver<a href="https://blog.csdn.net/zhaoxd200808501/article/details/77838933" target="_blank" rel="noopener noreferrer">远程调试技术<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <ul><li>gdbserver在目标系统中运行，gdb则在宿主机上运行</li></ul></li></ul> <h3 id="_6-gdb使用模拟器（免除远程调试）✔️"><a href="#_6-gdb使用模拟器（免除远程调试）✔️" class="header-anchor">#</a> 6.gdb使用模拟器（免除远程调试）✔️</h3> <h4 id="_6-1-代码调试-无qemu的情况"><a href="#_6-1-代码调试-无qemu的情况" class="header-anchor">#</a> 6.1.代码调试-无qemu的情况</h4> <ul><li>在riscv版本的gdb中使用<code>target sim</code>来进行</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> b gcc-main.c:43
Breakpoint <span class="token number">1</span> at 0x1d7b7: <span class="token function">file</span> /home/whoway/solvelbu/gcc/open_source/gcc-/gcc/gcc-main.c, line <span class="token number">43</span>.
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> run
Don't know how to run.  Try <span class="token string">&quot;help target&quot;</span><span class="token builtin class-name">.</span>
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> target sim		<span class="token comment">#gdb特有的功能？？</span>
Connected to the simulator.
<span class="token punctuation">(</span>gdb<span class="token punctuation">)</span> run
Starting program: /home/whoway/solvelbu/gcc/output/riscv32/bin/gcc 
warning: No program loaded.
Warning:
Cannot insert breakpoint <span class="token number">1</span>.
Cannot access memory at address 0x1d7b7
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="⭐️后台开发"><a href="#⭐️后台开发" class="header-anchor">#</a> ⭐️后台开发</h2> <ul><li>因为多进程和多线程调试，是后台程序调试不可避免而又比较困难的部分。</li></ul> <h3 id="_1-gdb多进程调试"><a href="#_1-gdb多进程调试" class="header-anchor">#</a> 1.gdb多进程调试</h3> <ul><li>如果一个进程通过fork系统调用创建了子进程，『gdb 会继续调试原来的进程，子进程则正常运行』</li> <li>那么该如何调试子进程呢?常用的方法有如下两种。</li></ul> <h4 id="_1-1-使用attach"><a href="#_1-1-使用attach" class="header-anchor">#</a> 1.1.使用attach</h4> <ul><li>比如，『子进程从本质上说也是一个进程』，因此我们可以用通用的gdb调试方法来调试它。</li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token function">ps</span> -ef <span class="token operator">|</span> <span class="token function">grep</span> 服务器程序名
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>我们可以先运行服务器，然后找到<strong>目标子进程的PID</strong>，再将其附加（attach）到gdb调试器上。</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>attach <span class="token number">4183</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="_1-2-使用调试器选项follow-fork-mode"><a href="#_1-2-使用调试器选项follow-fork-mode" class="header-anchor">#</a> 1.2.使用调试器选项<code>follow-fork-mode</code></h4> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>set follow<span class="token operator">-</span>fork<span class="token operator">-</span>mode mode
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>其中，mode的可选值是parent 和 child，分别表示调试父进程和子进程。</li></ul> <p>注意，和平常不一样了，需要指定
跟踪父进程还是子进程？
如果不设置，则默认跟踪父进程
<code>使用gdb调试的时候，gdb只能跟踪一个进程。</code>
可以在fork函数调用之前，通过指令设置gdb调试工具跟踪父进程或者是跟踪子进程。</p> <p>默认跟踪父进程。</p> <p><code>set follow-fork-mode child</code>命令设置gdb在fork之后跟踪子进程。
<code>set follow-fork-mode parent</code> 设置跟踪父进程。
注意，一定要在fork函数调用之前设置才有效。</p> <p>问，要是有多个子进程，怎么办？
可以设置断点，条件断点</p> <h3 id="_2-多线程调试"><a href="#_2-多线程调试" class="header-anchor">#</a> 2.多线程调试</h3> <ul><li>关于调试进程池和线程池程序的一个不错的方法，是先将池中的进程个数或线程个数减少至1，以观察程序的逻辑是否正确﹔然后逐步增加进程或线程的数量，以调试进程或线程的『同步』是否正确。</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>gdb有一组命令可辅助多线程程序的调试。下面我们仅列举其中常用的一些<span class="token operator">:</span>

info threads，显示当前可调试的所有线程。
    gdb会为每个线程分配一个ID，我们可以使用这个ID来操作对应的线程。ID前面有“<span class="token operator">*</span>”号的线程是当前被调试的线程。
thread ID，调试目标ID指定的线程。
set scheduler<span class="token operator">-</span>locking <span class="token punctuation">[</span> off <span class="token operator">|</span> on <span class="token operator">|</span> step <span class="token punctuation">]</span> 
    调试多线程程序时，默认除了被调试的线程在执行外，其他线程也在继续执行，但有的时候我们希望只让被调试的线程运行。这可以通过这个命令来实现。该命令设置scheduler<span class="token operator">-</span>locking 的值<span class="token operator">:</span> off表示不锁定任何线程，即所有线程都可以继续执行，这是默认值<span class="token punctuation">;</span> on表示只有当前被调试的线程会继续执行﹔step表示在单步执行的时候，只有当前线程会执行。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="参考资料"><a href="#参考资料" class="header-anchor">#</a> 参考资料</h2> <ul><li>游双，Linux高性能服务器编程</li> <li>公众号，编程珠玑，GDB调试指南</li> <li>GitHub上的<a href="https://github.com/skywind3000/awesome-cheatsheets/blob/master/tools/gdb.txt" target="_blank" rel="noopener noreferrer">gdb速查表<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>张云，<a href="https://m.douban.com/book/subject/4111413/" target="_blank" rel="noopener noreferrer">软件调试的艺术<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>调试GCC源码的官方Wiki：<a href="https://gcc.gnu.org/wiki/DebuggingGCC" target="_blank" rel="noopener noreferrer">https://gcc.gnu.org/wiki/DebuggingGCC<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li> <li>gdb 调试利器：<a href="https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html" target="_blank" rel="noopener noreferrer">https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/112.ad614f41.js" defer></script>
  </body>
</html>
